<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        li {
            list-style: none;
            cursor: pointer;
        }

        .tab {
            width: 600px;
            height: 300px;
            background-color: #ccc;
            margin: 0 auto;
        }

        .tab .tab-nav {
            display: flex;
            justify-content: space-around;
            align-items: center;
            width: 100%;
            height: 30px;
            background-color: cornflowerblue;
            font-size: 16px;
            color: #fff;
        }

        .tab-nav-active {
            color: red !important;
        }

        .tab .tab-content {
            height: 100%;
            background-color: chocolate;
        }

        .tab .tab-content .item {
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            display: none;
        }

        .tab .tab-content .tab-content-active {
            display: block;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
        }
    </style>
</head>

<body>
    <section class="tab">
        <ul class="tab-nav">
            <li class="tab-nav-active">我的</li>
            <li>首页</li>
            <li>购物车</li>
        </ul>
        <div class="tab-content">
            <div class="item tab-content-active">我的</div>
            <div class="item">首页</div>
            <div class="item">购物车</div>
        </div>
    </section>
    <script>
        const lis = document.querySelectorAll(".tab .tab-nav li")
        const divs = document.querySelectorAll(".tab .tab-content div")
        for (let i = 0; i < lis.length; i++) {
            lis[i].addEventListener("mouseenter", function () {
                document.querySelector(".tab-nav .tab-nav-active").classList.remove("tab-nav-active")
                this.classList.add("tab-nav-active")

                document.querySelector(".tab-content .tab-content-active").classList.remove("tab-content-active")
                divs[i].classList.add("tab-content-active")
            })
        }
    </script>
</body>

</html>